From cf5640aa7380fd5838a65c6567989dc9ecc9359d Mon Sep 17 00:00:00 2001 From: "Cliff L. Biffle" Date: Sun, 25 Sep 2016 13:53:07 -0700 Subject: [PATCH] Fall back to fs::copy when hard_link fails. Some filesystems don't allow hard links. Since Cargo's use of hard links is an optimization, and not necessary for correctness, it can fall back to a file copy when hard linking is not available. This is one possible solution to #3098. Caveat: this will try to copy if the hard link fails *for any reason*. It's not clear that there's a more surgical way of handling this; Unix tends to indicate the condition as "permission denied," not with a granular "links not supported by filesystem" error. --- src/cargo/ops/cargo_rustc/mod.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/cargo/ops/cargo_rustc/mod.rs b/src/cargo/ops/cargo_rustc/mod.rs index b36ed3ceb..59d1ec57f 100644 --- a/src/cargo/ops/cargo_rustc/mod.rs +++ b/src/cargo/ops/cargo_rustc/mod.rs @@ -317,9 +317,11 @@ fn rustc(cx: &mut Context, unit: &Unit) -> CargoResult { human(format!("failed to remove: {}", dst.display())) })); } - try!(fs::hard_link(&src, &dst).chain_error(|| { - human(format!("failed to link `{}` to `{}`", - src.display(), dst.display())) + try!(fs::hard_link(&src, &dst) + .or_else(|_| fs::copy(&src, &dst).map(|_| ())) + .chain_error(|| { + human(format!("failed to link or copy `{}` to `{}`", + src.display(), dst.display())) })); } } -- 2.30.2